/*
 * Copyright © 2024-2025 Wenze Wei
 *
 * This file is part of StadionOS.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License, v. 2.0.
 * You can obtain a copy of the GPL at
 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 */

#include "../include/process.h"

/**
 * @brief Waits for a child process to terminate.
 *
 * This function suspends the execution of the calling process until one of its child processes terminates.
 * It returns the process ID of the terminated child process and stores the exit status in the provided pointer.
 *
 * @param status A pointer to an integer where the exit status of the child process will be stored.
 * @return pid_t The process ID of the terminated child, or -1 on error.
 */
pid_t Swait(int *status) {
    return syscall(SYS_wait4, -1, status, 0, NULL);
}
